package com.qiyu.wakaka.config;


import org.springframework.web.multipart.MultipartFile;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 阿里云上传配置类
 */
public class ImageOss {

    private static final String HTTP_HEAD="https://";
    private static final String DOMAIN="oss-cn-beijing.aliyuncs.com";
    private static final String DREAM_DOMAIN="cdn.321kaka.cn";
    public static final String endpoint = HTTP_HEAD+DOMAIN;;
    public static final String accessKeyId = "LTAIjxi1HwOYYEJf";
    public static final String accessKeySecret = "e61QwzLFa2hiXdZotAVTTzcjNAFqtO";
    public static final String bucketName = "bucketdeanwu";
    public static final String fileNameHead = "DreamPics/";
    public static final String BASE_URL=HTTP_HEAD+DREAM_DOMAIN;



    /**
     * 生成oss文件名
     * @param file
     * @return
     */
    public static String buildFileName(MultipartFile file){
        //获取文件的原始名字
        String originalfileName = file.getOriginalFilename();
        String suffix = originalfileName.substring(originalfileName.lastIndexOf(".") + 1);
        String fileName=getDateTime();
        StringBuilder sb=new StringBuilder();
        sb.append(fileNameHead);
        sb.append(fileName);
        sb.append(".");
        sb.append(suffix);
        return sb.toString();
    }
    /**
     * 生成时间戳
     */
    private static String getDateTime(){
        DateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        return sdf.format(new Date());
    }


}
